/* 面试题 17.19. 消失的两个数字 */
/**
 * @param {number[]} nums
 * @return {number[]}
 */
/* 暴力 */
var missingTwo = function (nums) {
	const result = []
	const n = nums.length + 2
	for (let i = 1; i <= n; i++) {
		if (nums.includes(i)) continue
		result.push(i)
	}
	return result
}
var missingTwo = function (nums) {
	let n = nums.length + 2,
		cur = Math.floor((n * (n + 1)) / 2)
	for (const num of nums) cur -= num
	let sum = cur,
		t = Math.floor(cur / 2) // 缺失的两数一半
	cur = Math.floor((t * (1 + t)) / 2) // 求数组[1,t]的理论总和
	for (const num of nums) {
		// 求数组[1,t] 的实际和 理论与实际之差为缺失数之一
		if (num <= t) cur -= num
	}
	return [cur, sum - cur]
}
missingTwo([2, 3])
